package plp.functional2.expression;


import plp.expressions1.util.Tipo;
import plp.expressions2.expression.ExpBinaria;
import plp.expressions2.expression.Expressao;
import plp.expressions2.expression.Valor;
import plp.expressions2.expression.ValorBooleano;
import plp.expressions2.memory.AmbienteCompilacao;
import plp.expressions2.memory.AmbienteExecucao;
import plp.expressions2.memory.VariavelJaDeclaradaException;
import plp.expressions2.memory.VariavelNaoDeclaradaException;
import plp.functional1.expression.TuplaException;


;
/**
 * Um objeto desta classe representa uma Expressao de tamanho de String.
 */
public class ExpContainKey extends ExpBinaria {


	public ExpContainKey(Expressao esq, Expressao dir) {
		super(esq, dir, "inside");
		// TODO Auto-generated constructor stub
	}


	public Valor avaliar(AmbienteExecucao amb)
			throws VariavelJaDeclaradaException, VariavelNaoDeclaradaException,
			TuplaException, MapException {
		
		Valor valorEsq = getEsq().avaliar(amb);
		for (Expressao exp: ((ValorMap)super.getDir().avaliar(amb)).valor().keySet()) {
			if (exp.avaliar(amb).equals(valorEsq)) 
				return new ValorBooleano(true);
		}
		
		return new ValorBooleano(false);

	}

	
	protected boolean checaTipoElementoTerminal(AmbienteCompilacao amb)
			throws VariavelJaDeclaradaException, VariavelNaoDeclaradaException {
		return true;
	}


	public Tipo getTipo(AmbienteCompilacao amb) {
		return Tipo.TIPO_MAP;
	}
}
